package modelLayer;
import java.util.*;



public class LoanContainer
{
    // instance variables
	private static int index = 0;
	private static LoanContainer instance;
	private ArrayList<Loan> loans;

    
    private LoanContainer()
    {
        loans=new ArrayList();
    }
    
    public static LoanContainer getInstance()
    {
        if(instance==null)
        {
            instance = new LoanContainer();
        }
        return instance;
    }
    /**
     * This method shows that there aren't any loans.
     * @return boolean
     */
    public boolean isEmpty()
    {
        return loans==null;
    }
    public void addLoan(Loan loan)
    {
    	loan.setId(++index);
        loans.add(loan);
    }
    public void deleteLoan(Loan loan)
    {
        loans.remove(loan);
    }
    public Loan getLoan(int id)
    {
        
        
        if(!isEmpty())
        { boolean found=false;
            int index=0;
        while(!found&&index<loans.size())
        {
            if(loans.get(index).getId()==id)
            {
                found=true;
                return loans.get(index);
            }
            index++;
        }
    }
    
        return null;
    
    
    
    
    }
    public void showAll()
    {if(loans.size()!=0)
        {
        for(Loan currLoan:loans)
        {
            currLoan.showLoan();
        }
    }
    else
    System.out.println("You don't have any loans");
    }
}
